﻿@{
    ViewBag.Title = "CloneObject";
    Layout = "~/Views/Shared/_Page.cshtml";
}

<h2>Clone Object</h2>

<script type="text/javascript">
    /* Clone function. */
    function clone(object) {
        function F() { }
        F.prototype = object;
        return new F;
    }

    var CompoundObject = {
        string1: 'default value',
        childObject: {
            bool: true,
            num: 10
        },
        createChildObject: function (b, n) {
            var newChildObj = {
                bool: b,
                num: n
            };

            this.childObject = newChildObj;
        }
    }

    window.onload = function () {
        var compoundObjectClone = clone(CompoundObject);
        compoundObjectClone.string1 = 'clone value';
        compoundObjectClone.createChildObject(false, 5);

        ZEUS.DEBUG.log('Compound Object');
        ZEUS.DEBUG.log(CompoundObject.string1);
        ZEUS.DEBUG.log(CompoundObject.childObject.bool);
        ZEUS.DEBUG.log(CompoundObject.childObject.num);
        ZEUS.DEBUG.log('------------------------------------------');
        ZEUS.DEBUG.log('Cloned Compound Object');
        ZEUS.DEBUG.log(compoundObjectClone.string1);
        ZEUS.DEBUG.log(compoundObjectClone.childObject.bool);
        ZEUS.DEBUG.log(compoundObjectClone.childObject.num);
    }
    
</script>
